/*
 * $Id
 */

#ifdef __unix

#include <xp/bas/unxapi.h>
#include <xp/bas/errno.h>

#if defined(XP_USE_SYSCALL) && defined(XP_HAVE_SYS_SYSCALL_H)
#	include <sys/syscall.h>
#endif

xp_uid_t xp_getuid (void)
{
#ifdef SYS_getuid
	return syscall (SYS_getuid);
#else
	return getuid ();
#endif
}

xp_uid_t xp_geteuid (void)
{
#ifdef SYS_geteuid
	return syscall (SYS_geteuid);
#else
	return geteuid ();
#endif
}

xp_gid_t xp_getgid (void)
{
#ifdef SYS_getgid
	return syscall (SYS_getgid);
#else
	return getgid ();
#endif
}

xp_gid_t xp_getegid (void)
{
#ifdef SYS_getegid
	return syscall (SYS_getegid);
#else
	return getegid ();
#endif
}


xp_pid_t xp_getpid (void)
{
#ifdef SYS_getpid
	return syscall (SYS_getpid);
#else
	return getpid ();
#endif
}

xp_pid_t xp_getppid (void)
{
#ifdef SYS_getppid
	return syscall (SYS_getppid);
#else
	return getppid ();
#endif
}

xp_pid_t xp_setsid (void)
{
#ifdef SYS_setsid
	return syscall (SYS_setsid);
#else
	return setsid ();
#endif
}

xp_pid_t xp_getpgid (xp_pid_t pid)
{
#ifdef SYS_getpgid
	return syscall (SYS_getpgid, pid);
#else
	return getpgid (pid);
#endif
}

int xp_setpgid (xp_pid_t pid, xp_pid_t pgid)
{
#ifdef SYS_setpgid
	return syscall (SYS_setpgid, pid, pgid);
#else
	return setpgid (pid, pgid);
#endif
}

int xp_setpgrp (void)
{
	/*return setpgrp ();*/
#ifdef SYS_setpgid
	return syscall (SYS_setpgid, 0, 0);
#else
	return xp_setpgid (0, 0);
#endif
}

xp_pid_t xp_getpgrp (void)
{
#ifdef SYS_getpgid
	return syscall (SYS_getpgid, 0);
#else
	return xp_getpgid (0);
#endif
}

xp_pid_t xp_fork (void)
{
#ifdef SYS_fork
	return syscall (SYS_fork);
#else
	return fork ();
#endif
}

xp_pid_t xp_waitpid (xp_pid_t pid, int *status, int options)
{
#ifdef SYS_waitpid
	return syscall (SYS_waitpid, pid, status, options);
#else
	return waitpid (pid, status, options);
#endif
}

int xp_pipe (int pfd[2])
{
#ifdef SYS_pipe
	return syscall (SYS_pipe, pfd);
#else
	return pipe (pfd);
#endif
}

#endif
